#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QDebug"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //创建菜单栏，如果已经有了则用已经创建的菜单栏
    QMenuBar* menubar1=ui->menubar;
    this->setMenuBar(menubar1);
    //在菜单栏添加菜单
    QMenu* menu1=new QMenu("文件(&F)");
    ui->menubar->addMenu(menu1);
    QMenu* menu2=new QMenu("编辑(&E)");
    menubar1->addMenu(menu2);
    QMenu* menu3=new QMenu("帮助(&H)");
    ui->menubar->addMenu(menu3);
    QMenu* menu4=new QMenu("调试(&D)");
    menubar1->addMenu(menu4);
    //给菜单添加子菜单
    QMenu* menu5=new QMenu("子菜单1");
    menu1->addMenu(menu5);
    QMenu* menu6=new QMenu("子菜单2");
    menu2->addMenu(menu6);
    //添加菜单项
    QAction* action1=new QAction("另存为(&S)");
    menu1->addAction(action1);
    QAction* action2=new QAction("打开(&O)");
    menu1->addAction(action2);
    QAction* action3=new QAction("关闭(&C)");
    menu1->addAction(action3);

    //测试菜单项是否可用
    connect(action1,&QAction::triggered,this,&MainWindow::handle);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::handle()
{
    qDebug()<<"handle"<<endl;
}

